package com.graduation.project.controller.topic;

import com.graduation.project.entity.dto.task.SaveOrUpdateTaskDTO;
import com.graduation.project.entity.dto.task.ListTaskDTO;
import com.graduation.project.entity.dto.UpdateStatusDTO;
import com.graduation.project.service.topic.TaskService;
import com.graduation.project.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private TaskService taskService;

    /**
     * 新增课题-指导教师下拉数据（权限：新增课题权限、修改课题权限）
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('topic:myTask:add', 'topic:myTask:update', 'group:evaluator', 'group:defense')")
    @GetMapping("/get/listAdviserData")
    public ResultUtil<?> listAdviserData() {
        return taskService.listAdviserData();
    }

    /**
     * 获取课题详情（权限：查看详情权限、修改课题权限）
     * @param id 课题id
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('topic:task:details', 'topic:myTask:update')")
    @GetMapping("/get/getTaskDetails")
    public ResultUtil<?> getTaskDetails(@RequestParam("id") Long id) {
        return taskService.getTaskDetails(id);
    }

    /**
     * 新增课题（权限：新增课题权限）
     * @param input 新增|修改课题输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('topic:myTask:add')")
    @PostMapping("/post/addTask")
    public ResultUtil<?> addTask(@RequestBody SaveOrUpdateTaskDTO input) {
        return taskService.addTask(input);
    }

    /**
     * 修改课题（权限：修改课题权限）
     * @param input 新增|修改课题输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('topic:myTask:update')")
    @PutMapping("/put/updateTask")
    public ResultUtil<?> updateTask(@RequestBody SaveOrUpdateTaskDTO input) {
        return taskService.updateTask(input);
    }

    /**
     * 系主任审核课题（权限：系主任审核权限）
     * @param input 修改状态输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('topic:myTask:directorAudit')")
    @PutMapping("/put/directorAuditTask")
    public ResultUtil<?> directorAuditTask(@RequestBody UpdateStatusDTO input) {
        return taskService.directorAuditTask(input);
    }

    /**
     * 副院长审核课题（权限：副院长审核权限）
     * @param input 修改状态输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('topic:myTask:subdecanalAudit')")
    @PutMapping("/put/subdecanalAuditTask")
    public ResultUtil<?> subdecanalAuditTask(@RequestBody UpdateStatusDTO input) {
        return taskService.subdecanalAuditTask(input);
    }

    /**
     * 删除课题（权限：删除课题权限）
     * @param id 课题id
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('topic:myTask:delete')")
    @DeleteMapping("/delete/deleteTask")
    public ResultUtil<?> deleteTask(@RequestParam("id") Long id) {
        return taskService.deleteTask(id);
    }

    /**
     * （条件）查询课题
     * @param input 条件查询输入类
     * @return ResultUtil
     */
//    @PreAuthorize("hasAnyAuthority('topic:task:select')")
    @PostMapping("/post/listTaskByCondition")
    public ResultUtil<?> listTaskByCondition(@RequestBody ListTaskDTO input) {
        return taskService.listTaskByCondition(input);
    }

    /**
     * 学生选择课题（权限：选择课题权限）
     * @param id 课题id
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('topic:task:choose')")
    @PutMapping("/put/chooseTask")
    public ResultUtil<?> chooseTask(@RequestParam("id") Long id) {
        return taskService.chooseTask(id);
    }

    /**
     * 教师审核选题
     * @param input 修改状态输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('topic:myTask:teacherAudit')")
    @PutMapping("/put/teacherAuditTask")
    public ResultUtil<?> teacherAuditTask(@RequestBody UpdateStatusDTO input) {
        return taskService.teacherAuditTask(input);
    }

    /**
     * 学生取消选题
     * @param id 课题id
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('topic:myTask:cancel')")
    @PutMapping("/put/cancelChooseTask")
    public ResultUtil<?> cancelChooseTask(@RequestParam("id") Long id) {
        return taskService.cancelChooseTask(id);
    }
}
